home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / test / arc.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  2.7 KB  |  98 lines

  1. //
  2. // "$Id: arc.cxx,v 1.4 1999/01/07 19:17:48 mike Exp $"
  3. //
  4. // Arc drawing test program for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-1999 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  24. //
  25.  
  26. #include <FL/Fl.H>
  27. #include <FL/Fl_Double_Window.H>
  28. #include <FL/Fl_Hor_Value_Slider.H>
  29. #include <FL/fl_draw.H>
  30.  
  31. double args[6] = {140, 140, 50, 0, 360, 0};
  32. const char* name[6] = {"X", "Y", "R", "start", "end", "rotate"};
  33.  
  34. class Drawing : public Fl_Widget {
  35.   void draw() {
  36.     fl_clip(x(),y(),w(),h());
  37.     fl_color(FL_DARK3);
  38.     fl_rectf(x(),y(),w(),h());
  39.     fl_push_matrix();
  40.     if (args[5]) {
  41.       fl_translate(x()+w()/2.0, y()+h()/2.0);
  42.       fl_rotate(args[5]);
  43.       fl_translate(-(x()+w()/2.0), -(y()+h()/2.0));
  44.     }
  45.     fl_color(FL_WHITE);
  46.     fl_translate(x(),y());
  47.     fl_begin_complex_polygon();
  48.     fl_arc(args[0],args[1],args[2],args[3],args[4]);
  49.     fl_gap();
  50.     fl_arc(140,140,20,0,-360);
  51.     fl_end_complex_polygon();
  52.     fl_color(FL_RED);
  53.     fl_begin_line();
  54.     fl_arc(args[0],args[1],args[2],args[3],args[4]);
  55.     fl_end_line();
  56.     fl_pop_matrix();
  57.     fl_pop_clip();
  58.   }
  59. public:
  60.   Drawing(int X,int Y,int W,int H) : Fl_Widget(X,Y,W,H) {}
  61. };
  62.  
  63. Drawing *d;
  64.  
  65. void slider_cb(Fl_Widget* o, void* v) {
  66.   Fl_Slider* s = (Fl_Slider*)o;
  67.   args[long(v)] = s->value();
  68.   d->redraw();
  69. }
  70.  
  71. int main(int argc, char** argv) {
  72.   Fl_Double_Window window(300,500);
  73.   Drawing drawing(10,10,280,280);
  74.   d = &drawing;
  75.  
  76.   int y = 300;
  77.   for (int n = 0; n<6; n++) {
  78.     Fl_Slider* s = new Fl_Hor_Value_Slider(50,y,240,25,name[n]); y += 25;
  79.     if (n<3) {s->minimum(0); s->maximum(300);}
  80.     else if (n==5) {s->minimum(0); s->maximum(360);}
  81.     else {s->minimum(-360); s->maximum(360);}
  82.     s->step(1);
  83.     s->value(args[n]);
  84.     s->align(FL_ALIGN_LEFT);
  85.     s->callback(slider_cb, (void*)n);
  86.   }
  87.  
  88.   window.end();
  89.   window.show(argc,argv);
  90.   return Fl::run();
  91. }
  92.  
  93.  
  94. //
  95. // End of "$Id: arc.cxx,v 1.4 1999/01/07 19:17:48 mike Exp $".
  96. //
  97.  
  98.